package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.system.domain.dto.OaKeyworkDailyDTO;
import com.jcfk.system.domain.po.OaKeyworkInfo;
import com.jcfk.system.domain.query.OaKeyworkDailyQuery;
import com.jcfk.system.service.SysAnnexesFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import com.jcfk.system.domain.query.OaKeyworkInfoQuery;
import com.jcfk.system.domain.dto.OaKeyworkInfoDTO;
import com.jcfk.system.service.OaKeyworkInfoService;
import com.jcfk.common.core.utils.ExcelUtils;

import java.util.List;

/**
 * 重点工作
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-03-25
 */
@Api(tags = {"重点工作管理"})
@RestController
@RequestMapping("oakeyworkinfo")
public class OaKeyworkInfoController {
    @Autowired
    private OaKeyworkInfoService oaKeyworkInfoService;

    @Autowired
    private SysAnnexesFileService sysAnnexesFileService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<OaKeyworkInfoQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询重点工作")
    @PostMapping("/queryByPage")
    public RetPage<OaKeyworkInfoDTO> queryByPage(@RequestBody ReqPageParam<OaKeyworkInfoQuery> requestParam) {
        DataPage<OaKeyworkInfoDTO> page = new DataPage<OaKeyworkInfoDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                OaKeyworkInfoDTO.class);
        return oaKeyworkInfoService.queryByPage(page, requestParam.getData());
    }


    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<OaKeyworkInfoQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询重点工作")
    @PostMapping("/performance")
    public RetPage<OaKeyworkInfoDTO> performance(@RequestBody ReqPageParam<OaKeyworkInfoQuery> requestParam) {
        DataPage<OaKeyworkInfoDTO> page = new DataPage<OaKeyworkInfoDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                OaKeyworkInfoDTO.class);
        return oaKeyworkInfoService.performance(page, requestParam.getData());
    }

    /**
     * 获取工作列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OaKeyworkDailyQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取工作列表", notes = "获取工作列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<OaKeyworkInfoDTO>> getList(@RequestBody OaKeyworkInfoQuery query) {

        List<OaKeyworkInfoDTO> list = oaKeyworkInfoService.getList(query);

        return RetResult.ok(list);
    }


    /**
     * 重点工作
     * 根据id 查询详情
     */
    @ApiOperation("查询重点工作")
    @GetMapping("/get/{id}")
    public RetResult<OaKeyworkInfoDTO> get(@PathVariable("id") String id) {
        OaKeyworkInfoDTO item = oaKeyworkInfoService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理重点工作
     */
    @ApiOperation("保存重点工作")
    @PostMapping("/save")
    @RequestLogHeader(modular = "重点工作管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid OaKeyworkInfoDTO oaKeyworkInfo) {
        // 数据校验
        RetResult ret = oaKeyworkInfoService.isValid(oaKeyworkInfo);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(oaKeyworkInfo.getId())) {
            // 新增
            oaKeyworkInfoService.insert(oaKeyworkInfo);
        } else {
            // 更新
            oaKeyworkInfoService.update(oaKeyworkInfo);
        }
        return RetResult.ok();

    }

    /**
     * 批量删除重点工作
     */
    @ApiOperation("批量删除重点工作")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "重点工作管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody OaKeyworkInfoDTO oaKeyworkInfo) {
        return RetResult.ok(oaKeyworkInfoService.logicDeleteList(oaKeyworkInfo));
    }


    /**
     * 批量删除重点工作
     */
    @ApiOperation("修改状态")
    @PostMapping("/updateStatus")
    @RequestLogHeader(modular = "重点工作管理", businessType = "批量删除")
    public RetResult<?> updateStatus(@RequestBody OaKeyworkInfoDTO oaKeyworkInfo) {
        OaKeyworkInfo item = oaKeyworkInfoService.getById(oaKeyworkInfo.getId());
        item.setWorkStatus(oaKeyworkInfo.getWorkStatus());
        oaKeyworkInfoService.updateById(item);
        return RetResult.ok();
    }

}
